from django.conf import settings
from django.db import models

from home.models import Project
from user.models import User
from utils.common_base_models import BaseModel


# Create your models here.
class Order(BaseModel):
    """订单模型"""
    status_choices = (
        (0, '待付款'),
        (1, '已支付'),
        (2, '售后'),
        (3, '超时取消'),
    )
    pay_choices = (
        (1, '支付宝'),
        (2, '微信支付'),
    )
    subject = models.CharField(max_length=150, verbose_name="订单标题")
    total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="订单总价", default=0)
    out_trade_no = models.CharField(max_length=64, verbose_name="订单号", unique=True)  # 唯一，不能重复，后期可以根据订单号修改订单状态
    trade_no = models.CharField(max_length=64, null=True, verbose_name="交易流水号")  # 支付宝支付，生成流水号，存在着
    order_status = models.SmallIntegerField(choices=status_choices, default=0, verbose_name="订单状态")
    pay_type = models.SmallIntegerField(choices=pay_choices, default=2, verbose_name="支付方式")

    user = models.ForeignKey(User, related_name='order_user', on_delete=models.DO_NOTHING, db_constraint=False,
                             verbose_name="下单用户")
    project = models.ForeignKey(Project, related_name='order_Project', on_delete=models.DO_NOTHING, db_constraint=False,
                                verbose_name="商品", null=True, blank=True)

    class Meta:
        db_table = 'youzhu_Order'  # 指定表名
        verbose_name = '订单'  # 后台管理看到的中文
        verbose_name_plural = verbose_name

    def __str__(self):  # 打印对象，显示的
        return self.subject

